﻿using System.Windows.Forms;

namespace System.Windows.Forms
{
	public enum StartUPType
	{
		Non,
		New,
		Open,
		History
	}

	public partial class FormStartUp : Form
	{
		StartUPType m_type = StartUPType.Non;

		public StartUPType Type
		{
			get
			{
				return m_type;
			}
		}

		public int HistoryIndex
		{
			get
			{
				if (treeView1.SelectedNode.Index < 2)
					return -1;
				else
					return treeView1.SelectedNode.Index - 2;
			}
		}

		public string[] HistoryList
		{
			set
			{
				if (value == null)
					return;

				int i = 0;
				int sum = value.Length;
				TreeNode[] oNodes = new TreeNode[sum];
				foreach (string shortFilepath in value)
				{
					oNodes[i] = new TreeNode(shortFilepath);
					i++;
				}
				treeView1.Nodes.AddRange(oNodes);
			}
		}

		public FormStartUp()
		{
			InitializeComponent();
		}

		private void treeView1_KeyDown(object sender, KeyEventArgs e)
		{
			switch (e.KeyCode)
			{
				case Keys.Enter:
					SelectType(treeView1.SelectedNode.Index);
					this.DialogResult = DialogResult.OK;
					break;
				case Keys.Escape:
					this.DialogResult = DialogResult.Cancel;
					break;
			}
		}

		private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
		{
			SelectType(e.Node.Index);
		}

		private void SelectType(int index)
		{
			switch (index)
			{
				case 0:
					m_type = StartUPType.New;
					break;
				case 1:
					m_type = StartUPType.Open;
					break;
				default:
					m_type = StartUPType.History;
					break;
			}

			this.DialogResult = DialogResult.OK;
		}
	}
}
